using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Tools;
using Pixysoft.Framework.Verifications;
using Pixysoft.Framework.Noebe;
using Pixysoft.Weblications.Sango.Entities;

namespace Pixysoft.Weblications.Sango.Environment
{

    public class SysTacticalHelper
    {
        private static List<Sys_Tactical> orms = new List<Sys_Tactical>();

        private static List<Sys_Tacticalpos> posorms = new List<Sys_Tacticalpos>();

        public static void initialize()
        {
            orms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Sys_Tactical>();

            posorms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Sys_Tacticalpos>();

            LoggerHelper.Info("initialize Sys_Tactical.count {0}, Sys_Tacticalpos.count {1}", orms.Count, posorms.Count);
        }

        public static Sys_Tactical search(long typecode)
        {
            foreach (Sys_Tactical orm in orms)
            {
                if (orm.Tacticaltypecode == typecode)
                    return orm;
            }

            throw Exceptions.VerificationFailedException(typecode);
        }

        public static List<Sys_Tactical> searchAll()
        {
            return orms;
        }

        public static List<Sys_Tacticalpos> searchPositions(long typecode)
        {
            List<Sys_Tacticalpos> list = new List<Sys_Tacticalpos>();

            foreach (Sys_Tacticalpos orm in posorms)
            {
                if (orm.Tacticaltypecode == typecode)
                    list.Add(orm);
            }

            return list;
        }

        public static Sys_Tactical trySearchByLevel(long requiredlevel)
        {
            foreach (Sys_Tactical tactical in orms)
            {
                if (tactical.Requiredlevel == requiredlevel)
                    return tactical;
            }

            return null;
        }
    }
}